package com.hmf.config;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@Configuration
@MapperScan("com.hmf.dao")
@ComponentScan("com.hmf.service")
public class SpringConfig {
    @Bean
    public SqlSessionFactory getSqlSessionFactory() throws Exception {
        // 1. 加载核心配置文件
        InputStream inputStream = Resources.getResourceAsStream("jdbc.properties");
        Properties properties=new Properties();
        properties.load(inputStream);
        String resource="mybatis-config.xml";
        InputStream inputStream2=Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream2,properties);
        return sqlSessionFactory;
    }
}
